<?php
declare(strict_types=1);

namespace App\Controller\Admin;

use Hyperf\Di\Annotation\Inject;
use App\Controller\AbstractController;
use App\Service\AdminService;
use \Psr\Http\Message\ResponseInterface;

class AuthController extends AbstractController
{
    /**
     * @Inject
     * @var AdminService
     */
    protected $adminService;

    /**
     * @return ResponseInterface
     */
    public function login()
    {
        return $this->render->render('admin/auth/login.twig');
    }

    /**
     * @return ResponseInterface
     */
    public function postLogin()
    {
        $username = $this->request->post('username');
        $password = $this->request->post('password');
        $res = $this->adminService->login($username, $password);

        return $this->response->json($res);
    }

    /**
     * 注销登录
     * @return ResponseInterface
     */
    public function logout()
    {
        $res = $this->adminService->logout();

        return $this->response->json($res);
    }
}